Repository navigation
FIX GCG: compare stripped suffixes and survive an all-rejected candidate batch - #4637
Open
K L Aadithya (Aadithya-kl) wants to merge 11 commits into
Open
K L Aadithya (Aadithya-kl) wants to merge 11 commits into
K L Aadithya (Aadithya-kl) wants to merge 11 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Both candidate filters return a stripped fallback suffix that can re-tokenize differently from the retained control tokens, causing the reported loss to score different token IDs.
1 open issue
What changed in this PR
This PR addresses #4545 and #4546 in PyRIT’s GCG candidate filtering, keeping the default and legacy implementations aligned.
Changes:
- Compare stripped suffixes to reject unchanged candidates while preserving decoded separator spaces.
- Fall back to the current control when all candidates are rejected, with a clear legacy error when no fallback is available.
- Add regression tests covering both filtering paths.
| File | Description |
|---|---|
tests/unit/executor/promptgen/gcg/test_default_implementations.py |
Adds regression and parity tests for unchanged candidates and all-rejected batches. |
pyrit/executor/promptgen/gcg/default_implementations.py |
Updates suffix comparison and adds fallback padding. |
pyrit/executor/promptgen/gcg/attack/base/attack_manager.py |
Applies equivalent legacy filtering changes and documents the missing-fallback error. |
Review effort: Balanced
| candidates = candidates + [candidates[-1]] * (len(candidate_tokens) - len(candidates)) | ||
| # When every row is rejected, fall back to the current suffix so | ||
| # the step re-scores it instead of indexing an empty list. | ||
| pad = candidates[-1] if candidates else current_control |
Contributor
Author
|
Addressed the Copilot review (fallback scored stripped text):
GCG unit suite: 605 passed. |
The keyword-only migration in microsoft#4693 makes control_cand keyword-only; using the keyword form now keeps these new tests valid in either merge order. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ol decode Mirrors the filter_candidates docstring so the legacy fallback also re-tokenizes to the current control ids. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
Fixes #4545 and fixes #4546: two bugs in the GCG candidate filter, fixed identically in
LengthPreservingFilter.filter_candidatesand the legacyMultiPromptAttack.get_filtered_candsso the two stay in parity.current_controlcomes from the strippedcontrol_str, but candidates are decoded with their leading separator space (kept on purpose since FIX GCG: render decoded controls without a second separator space #3581). The no-op check now compares stripped forms, so an unchanged suffix is dropped instead of taking a scoring slot. The fix is in the comparison, not the decode.IndexError. The filter now pads with the current control, so the step re-scores the current suffix and the run continues (the proposer already documentscurrent_control_stras the fallback for length filters). The legacy path raises a clearRuntimeErrorif it has nocurr_controlto fall back to.test_default_implementations.pycover both cases on both code paths and fail without the fix.#4547 (
>vs>=vocab clamp) is left to its existing PR.🤖 Generated with Claude Code